import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static char[] choose = new char[]{'A','B','C','D'};
    public static Map<Character, Integer> countMap = new HashMap<>();

    public static void main(String[] args) {
        long startTime=System.currentTimeMillis();
        char[] answer = new char[10];
        try{
            add(answer, 0);
        }catch (RuntimeException e){
            System.out.println("用时"+ (System.currentTimeMillis()-startTime)+"ms; " + e.getMessage());
        }

    }

    public static void add(char[] answer, int i){
        for(char c : choose) {
            answer[i] = c;
            if(i==9){
                if(check(answer)){
                    throw new RuntimeException("正确答案:"+ Arrays.toString(answer));
                }
            }else{
                add(answer, i+1);
            }
        }
    }

    private static boolean check(char[] answer) {
        return check1(answer) &&
                check2(answer) &&
                check3(answer) &&
                check4(answer) &&
                check5(answer) &&
                check6(answer) &&
                check7(answer) &&
                check8(answer) &&
                check9(answer) &&
                check10(answer);
    }

    private static boolean check1(char[] answer){
        return true;
    }

    private static boolean check2(char[] answer){
        char answer2;
        switch (answer[1]){
            case 'A': answer2='C'; break;
            case 'B': answer2='D'; break;
            case 'C': answer2='A'; break;
            case 'D': answer2='B'; break;
            default : answer2='0'; break;
        }
        return answer2==answer[4];
    }
    private static boolean check3(char[] answer){
        return true;
    }
    private static boolean check4(char[] answer){
        switch(answer[3]){
            case 'A': return answer[0] == answer[4];
            case 'B': return answer[1] == answer[6];
            case 'C': return answer[0] == answer[8];
            case 'D': return answer[5] == answer[9];
            default: return false;
        }
    }
    private static boolean check5(char[] answer){
        char answer5 = answer[4];
        switch(answer5){
            case 'A': return answer5==answer[7];
            case 'B': return answer5==answer[3];
            case 'C': return answer5==answer[8];
            case 'D': return answer5==answer[6];
            default: return false;
        }
    }
    private static boolean check6(char[] answer){
        switch(answer[5]){
            case 'A': return answer[1]==answer[7] && answer[3]==answer[7];
            case 'B': return answer[0]==answer[7] && answer[5]==answer[7];
            case 'C': return answer[2]==answer[7] && answer[9]==answer[7];
            case 'D': return answer[4]==answer[7] && answer[8]==answer[7];
            default: return false;
        }
    }
    private static boolean check7(char[] answer){
        char answer7Content;
        switch (answer[6]){
            case 'A': answer7Content='C'; break;
            case 'B': answer7Content='B'; break;
            case 'C': answer7Content='A'; break;
            case 'D': answer7Content='D'; break;
            default: answer7Content='0';
        }
        return answerCountMin(answerCount(answer))==answer7Content;
    }
    private static boolean check8(char[] answer){
        char an = '0';
        switch (answer[7]){
            case 'A': an=answer[6]; break;
            case 'B': an=answer[4]; break;
            case 'C': an=answer[1]; break;
            case 'D': an=answer[9]; break;
            default: an='0';
        }
        return an-answer[0]!=-1 && an-answer[0] !=1;
    }
    private static boolean check9(char[] answer){
        boolean same16 = answer[0]==answer[5];
        char answerx = '0';
        switch (answer[8]){
            case 'A': answerx = answer[5]; break;
            case 'B': answerx = answer[9]; break;
            case 'C': answerx = answer[1]; break;
            case 'D': answerx = answer[8]; break;
            default : answerx = '0'; break;
        }
        boolean samex5 = answer[4] == answerx;
        return same16 == !samex5;
    }
    private static boolean check10(char[] answer){
        int diff=answerCountDiff(countMap);
        switch (answer[9]){
            case 'A': return diff==3;
            case 'B': return diff==2;
            case 'C': return diff==4;
            case 'D': return diff==1;
            default : return false;
        }
    }

    private static Map<Character, Integer> answerCount(char[] answer){
        countMap.put('A',0);
        countMap.put('B',0);
        countMap.put('C',0);
        countMap.put('D',0);
        for(char a : answer){
            countMap.put(a, countMap.get(a)+1);
        }
        return countMap;

    }

    private static int answerCountMin(Map<Character, Integer> countMap){
        char minChar = '0';
        int minCount = 10;
        for(Map.Entry<Character, Integer> entry : countMap.entrySet()){
            if(entry.getValue()<=minCount){
                minCount = entry.getValue();
                minChar = entry.getKey();
            }
        }
        return minChar;
    }

    private static int answerCountDiff(Map<Character, Integer> countMap){
        char minChar = '0';
        int minCount = 10;
        for(Map.Entry<Character, Integer> entry : countMap.entrySet()){
            if(entry.getValue()<=minCount){
                minCount = entry.getValue();
                minChar = entry.getKey();
            }
        }
        char maxChar = '0';
        int maxCount = 0;
        for(Map.Entry<Character, Integer> entry : countMap.entrySet()){
            if(entry.getValue()>=maxCount){
                maxCount = entry.getValue();
                maxChar = entry.getKey();
            }
        }
        return maxCount-minCount;
    }

}
